﻿using System;

namespace _08_Decorator
{
    /// <summary>
    /// 装饰器模式
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            Cake cake = new CheeseCake(); //生成一个芝士蛋糕
            Decorator candle = new WithCandle(cake);  //在蛋糕上加点蜡烛
            Decorator flower = new WithFlower(candle); //在加点鲜花
            flower.Show();  //蛋糕做好了看一下
            Console.ReadKey();
        }
    }
    abstract  class Cake
    {
        public abstract void Show();
    }
    class CheeseCake : Cake
    {
        public override void Show()
        {
            Console.WriteLine("This is a CheeseCake");
        }
    }
    class FruitCake : Cake
    {
        public override void Show()
        {
            Console.WriteLine("This is a FruitCake");
        }
    }
    abstract class Decorator : Cake
    {
        Cake cake;
        public Decorator(Cake c)
        {
            cake = c;
        }
        public override void Show()
        {
            cake.Show();
            SomethingAdd();
        }
        protected abstract void SomethingAdd();
    }
    class WithCandle : Decorator
    {
        Cake cake;
        public WithCandle(Cake c):base(c)
        {
            cake = c;
        }
        protected override void SomethingAdd()
        {
            Console.WriteLine("Add some candles on this cake");
        }
    }
    class WithFlower : Decorator
    {
        Cake cake;
        public WithFlower(Cake c) : base(c)
        {
            cake = c;
        }
        protected override void SomethingAdd()
        {
            Console.WriteLine("Add some flowers on this cake");
        }
    }
}
